package com.jy.rhin.facade.infra.controller.notification.assembler;

import com.jy.rhin.domain.notification.topic.entity.EnumFilterType;
import com.jy.rhin.infra.repo.notfication.topic.po.TopicPO;
import com.jy.rhin.infra.repo.notfication.topic.po.TopicPropertiesPO;
import com.jy.rhin.infra.repo.notfication.topic.po.TopicQueryFilterPO;
import com.jy.rhin.infra.repo.notfication.topic.po.TopicQueryPO;
import com.jy.rhin.sdk.dto.notification.resp.*;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;

/**
 * @Description:
 * @Author: lww
 * @Date: 2022/6/29 11:26
 */
public class TopicAssembler {

    private TopicAssembler() {
    }

    public static TopicShortDto toShortDTO(TopicPO topicPo) {
        TopicShortDto dto = new TopicShortDto();
        BeanUtils.copyProperties(topicPo, dto);
        return dto;
    }

    public static TopicQueryDto toQueryDTO(TopicQueryPO topicQueryPo) {
        TopicQueryDto dto = new TopicQueryDto();
        BeanUtils.copyProperties(topicQueryPo, dto);
        return dto;
    }

    public static TopicQueryFilterDto toQueryFilterDTO(TopicQueryFilterPO topicQueryFilterPo) {
        TopicQueryFilterDto dto = new TopicQueryFilterDto();
        BeanUtils.copyProperties(topicQueryFilterPo, dto);
        dto.setRangeCode(topicQueryFilterPo.getFilterCode());
        dto.setDicList(new ArrayList<>());
        dto.setXmlPath(topicQueryFilterPo.getSourcePath());
        dto.setJsonPath(topicQueryFilterPo.getTargetPath());
        dto.setRangeFlag(EnumFilterType.valueOf(topicQueryFilterPo.getFilterType()) == EnumFilterType.TEXT ? Boolean.FALSE : Boolean.TRUE);
        return dto;
    }

    public static TopicDetailDto toDetailDTO(TopicPO topicPo) {
        TopicDetailDto dto = new TopicDetailDto();
        BeanUtils.copyProperties(topicPo, dto);
        return dto;
    }

    public static TopicPropertiesDto toPropertiesDTO(TopicPropertiesPO topicPropertiesPo) {
        TopicPropertiesDto dto = new TopicPropertiesDto();
        BeanUtils.copyProperties(topicPropertiesPo, dto);
        dto.setJsonPath(topicPropertiesPo.getTargetPath());
        dto.setXmlPath(topicPropertiesPo.getSourcePath());
        return dto;
    }
}
